﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Runtime.Serialization
{
  [AttributeUsage(AttributeTargets.Class)]
  sealed class CerealizableAttribute : Attribute
  {
    // See the attribute guidelines at 
    //  http://go.microsoft.com/fwlink/?LinkId=85236
    private readonly Type _serializationFactory;
    private readonly ISerializationFactory _factory;

    public ISerializationFactory Factory
    {
      get { return _factory; }
    } 

    // This is a positional argument
    public CerealizableAttribute(Type serializationFactory)
    {
      if (!typeof(ISerializationFactory).IsAssignableFrom(serializationFactory))
        throw new Exception(String.Format("Type {0} does not implement ISerializationFactory"));
      this._serializationFactory = serializationFactory;
      _factory = Activator.CreateInstance(serializationFactory) as ISerializationFactory;
    }

    public Type PositionalString
    {
      get { return _serializationFactory; }
    }
  }
}
